# -*- coding:utf-8 -*-
from datetime import datetime

from django.db import models
from ckeditor_uploader.fields import RichTextUploadingField

from users.models import UserProfile


class MenuType(models.Model):
    name = models.CharField(u'菜系名', max_length=20)
    number = models.IntegerField(u'数量', default=0)

    class Meta:
        verbose_name = u'菜系'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.name


class Menu(models.Model):
    name = models.CharField(u'菜名', max_length=50)
    user = models.ForeignKey(UserProfile, verbose_name=u'用户')
    image = models.ImageField(u'图片', upload_to='menu/%Y/%m', blank=True)
    menu_tpye = models.ForeignKey(MenuType, verbose_name=u'类型', blank=True, null=True)
    ingredients = models.CharField(u'原料', max_length=200, blank=True)
    details = RichTextUploadingField(u'制作过程')
    click_number = models.IntegerField(u'查看次数', default=0)
    add_time = models.DateTimeField(u'添加时间', default=datetime.now)

    class Meta:
        verbose_name = u'菜单'
        verbose_name_plural = verbose_name

    def __unicode__(self):
        return self.name
